<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Roll back a transaction</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.cubrid-rollback" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">cubrid_rollback</h1>
  <p class="verinfo">(PECL CUBRID &gt;= 8.3.0)</p><p class="refpurpose"><span class="refname">cubrid_rollback</span> &mdash; <span class="dc-title">Roll back a transaction</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.cubrid-rollback-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>cubrid_rollback</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$conn_identifier</code></span>  
   ) : <span class="type">bool</span></div>

  <p class="para rdfs-comment">
    The <span class="function"><strong>cubrid_rollback()</strong></span> function executes rollback on the
    transaction pointed by <code class="parameter">conn_identifier</code>, currently in
    progress.
  </p>
  <p class="para">
    Connection to server is closed after calling
    <span class="function"><strong>cubrid_rollback()</strong></span>. Connection handle, however, is
    still valid.
  </p>
 </div>


<div class="refsect1 parameters" id="refsect1-function.cubrid-rollback-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
  <dl>

    
  <dt>
<code class="parameter">conn_identifier</code></dt>

  <dd>
<p class="para">Connection identifier.</p></dd>

   
  </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.cubrid-rollback-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
    <strong><code>TRUE</code></strong>, when process is successful.
  </p>
  <p class="para">
    <strong><code>FALSE</code></strong>, when process is unsuccessful.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.cubrid-rollback-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-1144">
   <p><strong>Example #1 <span class="function"><strong>cubrid_rollback()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"127.0.0.1"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">33000</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"demodb"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"dba"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">cubrid_set_autocommit</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,</span><span style="color: #0000BB">false</span><span style="color: #007700">);<br /><br />@</span><span style="color: #0000BB">cubrid_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"DROP&nbsp;TABLE&nbsp;publishers"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$sql&nbsp;</span><span style="color: #007700">=&nbsp;&lt;&lt;&lt;EOD<br /></span><span style="color: #DD0000">CREATE&nbsp;TABLE&nbsp;publishers(<br />pub_id&nbsp;CHAR(3),&nbsp;<br />pub_name&nbsp;VARCHAR(20),&nbsp;<br />city&nbsp;VARCHAR(15),&nbsp;<br />state&nbsp;CHAR(2),&nbsp;<br />country&nbsp;VARCHAR(15)<br />)<br /></span><span style="color: #007700">EOD;<br /><br />if&nbsp;(!</span><span style="color: #0000BB">cubrid_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$sql</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"Error&nbsp;facility:&nbsp;%d\nError&nbsp;code:&nbsp;%d\nError&nbsp;msg:&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">cubrid_error_code_facility</span><span style="color: #007700">(),&nbsp;</span><span style="color: #0000BB">cubrid_error_code</span><span style="color: #007700">(),&nbsp;</span><span style="color: #0000BB">cubrid_error_msg</span><span style="color: #007700">());<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">cubrid_disconnect</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;exit;<br />}<br /><br /></span><span style="color: #0000BB">$req&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_prepare</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"INSERT&nbsp;INTO&nbsp;publishers&nbsp;VALUES(?,&nbsp;?,&nbsp;?,&nbsp;?,&nbsp;?)"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$id_list&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"P01"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"P02"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"P03"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"P04"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$name_list&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"Abatis&nbsp;Publishers"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Core&nbsp;Dump&nbsp;Books"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Schadenfreude&nbsp;Press"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Tenterhooks&nbsp;Press"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$city_list&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"New&nbsp;York"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"San&nbsp;Francisco"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Hamburg"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Berkeley"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$state_list&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"NY"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"CA"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">NULL</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"CA"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$country_list&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"USA"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"USA"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Germany"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"USA"</span><span style="color: #007700">);<br /><br />for&nbsp;(</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$size&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">count</span><span style="color: #007700">(</span><span style="color: #0000BB">$id_list</span><span style="color: #007700">);&nbsp;</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">&lt;&nbsp;</span><span style="color: #0000BB">$size</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">$i</span><span style="color: #007700">++)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">cubrid_bind</span><span style="color: #007700">(</span><span style="color: #0000BB">$req</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$id_list</span><span style="color: #007700">[</span><span style="color: #0000BB">$i</span><span style="color: #007700">]);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">cubrid_bind</span><span style="color: #007700">(</span><span style="color: #0000BB">$req</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$name_list</span><span style="color: #007700">[</span><span style="color: #0000BB">$i</span><span style="color: #007700">]);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">cubrid_bind</span><span style="color: #007700">(</span><span style="color: #0000BB">$req</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$city_list</span><span style="color: #007700">[</span><span style="color: #0000BB">$i</span><span style="color: #007700">]);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">cubrid_bind</span><span style="color: #007700">(</span><span style="color: #0000BB">$req</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">4</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$state_list</span><span style="color: #007700">[</span><span style="color: #0000BB">$i</span><span style="color: #007700">]);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">cubrid_bind</span><span style="color: #007700">(</span><span style="color: #0000BB">$req</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">5</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$country_list</span><span style="color: #007700">[</span><span style="color: #0000BB">$i</span><span style="color: #007700">]);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!(</span><span style="color: #0000BB">$ret&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$req</span><span style="color: #007700">)))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br />if&nbsp;(!</span><span style="color: #0000BB">$ret</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">cubrid_rollback</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">cubrid_commit</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$req&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"SELECT&nbsp;*&nbsp;FROM&nbsp;publishers"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;(</span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_fetch_assoc</span><span style="color: #007700">(</span><span style="color: #0000BB">$req</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%-3s&nbsp;%-20s&nbsp;%-15s&nbsp;%-3s&nbsp;%-15s\n"</span><span style="color: #007700">,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$result</span><span style="color: #007700">[</span><span style="color: #DD0000">"pub_id"</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">$result</span><span style="color: #007700">[</span><span style="color: #DD0000">"pub_name"</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">$result</span><span style="color: #007700">[</span><span style="color: #DD0000">"city"</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">$result</span><span style="color: #007700">[</span><span style="color: #DD0000">"state"</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">$result</span><span style="color: #007700">[</span><span style="color: #DD0000">"country"</span><span style="color: #007700">]);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #0000BB">cubrid_disconnect</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
   </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
P01 Abatis Publishers    New York        NY  USA            
P02 Core Dump Books      San Francisco   CA  USA            
P03 Schadenfreude Press  Hamburg             Germany        
P04 Tenterhooks Press    Berkeley        CA  USA            
</pre></div>
   </div>
  </div>
 </div>


   <div class="refsect1 seealso" id="refsect1-function.cubrid-rollback-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist"> 
    <li class="member"><span class="function"><a href="cubrid_commit.html" class="function" rel="rdfs-seeAlso">cubrid_commit()</a> - Commit a transaction</span></li> 
    <li class="member"><span class="function"><a href="cubrid_disconnect.html" class="function" rel="rdfs-seeAlso">cubrid_disconnect()</a> - Close a database connection</span></li>     
   </ul>
  </p>
  </div>


</div></div></div></body></html>